module.exports = (sequelize, DataTypes) => {
  const HealthReminder = sequelize.define('HealthReminder', {
    id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true
    },
    user_id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: '关联用户ID'
    },
    member_id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: '关联家庭成员ID'
    },
    title: {
      type: DataTypes.STRING,
      allowNull: false,
      comment: '提醒标题'
    },
    content: {
      type: DataTypes.TEXT,
      allowNull: true,
      comment: '提醒内容'
    },
    type: {
      type: DataTypes.ENUM('medication', 'checkup', 'exercise', 'diet', 'other'),
      defaultValue: 'other',
      comment: '提醒类型：服药、体检、运动、饮食、其他'
    },
    remind_time: {
      type: DataTypes.TIME,
      allowNull: false,
      comment: '提醒时间'
    },
    remind_date: {
      type: DataTypes.DATEONLY,
      allowNull: true,
      comment: '提醒日期，一次性提醒需要'
    },
    repeat_type: {
      type: DataTypes.ENUM('once', 'daily', 'weekly', 'monthly', 'custom'),
      defaultValue: 'once',
      comment: '重复类型：一次性、每天、每周、每月、自定义'
    },
    repeat_value: {
      type: DataTypes.STRING,
      allowNull: true,
      comment: '重复值，如周一、周三、周五等'
    },
    status: {
      type: DataTypes.ENUM('active', 'completed', 'paused'),
      defaultValue: 'active',
      comment: '提醒状态：活跃、已完成、已暂停'
    },
    start_date: {
      type: DataTypes.DATEONLY,
      allowNull: true,
      comment: '开始日期'
    },
    end_date: {
      type: DataTypes.DATEONLY,
      allowNull: true,
      comment: '结束日期'
    },
    last_reminded_at: {
      type: DataTypes.DATE,
      allowNull: true,
      comment: '上次提醒时间'
    }
  }, {
    tableName: 'health_reminders',
    timestamps: true,
    paranoid: true
  });

  HealthReminder.associate = function(models) {
    HealthReminder.belongsTo(models.User, {
      foreignKey: 'user_id',
      as: 'user'
    });
    
    HealthReminder.belongsTo(models.FamilyMember, {
      foreignKey: 'member_id',
      as: 'member'
    });
  };

  return HealthReminder;
}; 